<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="js/vue.js"></script>
    <title>获取焦点-播放音乐</title>
</head>

<body>
    <div id="app">
        <input type="text" placeholder="请输入内容" @focus="playMusic">
    </div>
    <script>
        new Vue({
            el: "#app",
            methods: {
                playMusic() {
                    //创建一个Audio对象，设置音频文件路径
                    const audio = new Audio("https://dict.youdao.com/dictvoice?type=1&audio=tutorial");
                    //播放音频
                    audio.play().catch(error => {
                        console.error("播放音频时遇到问题：", error)
                    })
                }
            }
        })
    </script>
</body>

</html>